define(
		[ "PDUtilDir/util", "PDUtilDir/slidebar",
				"PDUtilDir/inputSelect",
				"PDUtilDir/fileupload/singleFileUpload",
				"css!AppPathDir/account/accountInfos/views/css/css" ],
		function(Util, Slidebar, inputSelect, MFU) {
			function uploadSupportInit($scope, $compile) {
				return new uploadSupport($scope, $compile);
			}
			function uploadSupport($scope, $compile) {
				this.$scope = $scope;
				this.$compile = $compile;
			}
			uploadSupport.fn = uploadSupport.prototype;
			uploadSupport.fn.init = function() {
				this.entity = new Array();
				this.cache = {
					suffix : ['rmvb', 'rm', 'wmv', 'avi', '3gp', 'mp4', 'flv', 'swf', 'ipod', 'psp', 'gif'],
					products: new Array()
				};
				this.bind = {};
			};
			
			uploadSupport.fn.run = function() {
				var _this = this;
				_this.init();
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer()
							+ "/static/app/video/videoInfos/views/add.html",
//					close : true,
					$scope : this.$scope,
					$compile : this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			uploadSupport.fn.initialization = function() {
				var _this = this;
//				_this.$scope.$watch("uploadSupport.entity", function(values){
//					console.info(values);
//				});
				// 初始化支付类型下拉框
				if(this.cache.products.length > 0){
					inputSelect.dropCache();
					inputSelect({
						id : "productName",
						key : {
							id : "id",
							name : "name",
							data : "data",
						},
						data : _this.cache.products,
						simpleData : true,
						searchAble : false,
						callback : function(id,obj) {
							_this.bind.productId = id[0];
							_this.bind.productName = obj[0].name;
							_this.$scope.uploadVideoForm.productId.$setViewValue(_this.bind.productId);
						}
					});
				}else{
					$.ajax({
						url : getServer() + "/flea/hclv/product/findByDeptIdForSelect.htmls",
						success : function(data) {
                            if (data.status != 200) {
                                return;
                            }
							_this.cache.products = data.data;
							inputSelect.dropCache();
							inputSelect({
								id : "productName",
								key : {
									id : "id",
									name : "name",
									data : "data",
								},
								data : _this.cache.products,
								simpleData : true,
								searchAble : false,
								callback : function(id,obj) {
									_this.bind.productId = id[0];
									_this.bind.productName = obj[0].name;
								}
							});
						}
					});
				}
				var abc = MFU.init({
	                placeAt:"video_upload",
	                allowDelete:true,
	                allowMC:true,
	                onUploadSuccess:function(file){
	                	_this.bind.videos = {'key':file.name, 'resouceId':file.swordFileId,'path':file.swordFilePath};
	                	_this.bind.videoOk = true;
	                	_this.$scope.uploadVideoForm.videoOk.$setViewValue(_this.bind.videoOk);
	                },
	                onFileQueued: function(file){
	                	this.webUploader.upload();
	                	_this.cache.fileload = this;
	                	if(_this.cache.suffix.indexOf(file.ext.toLowerCase()) < 0){
	                		Util.alert("视频格式不正确，请重新选择！");
	                		this.remove();
	                	}
	                },
	             // 只允许选择图片文件。
//	                accept: {
//	                    title: 'Images',
//	                    extensions: 'jpg,png',
//	                    mimeTypes: 'image/*'
//	                },
	                onError: function(errorType,file){
	                	// console.info(errorType);
	                	// console.info(file);
	                }
	            });
				// console.info(abc);
//				abc.webUploader.on("error", function(errorType,file){
//                	console.info(errorType);
//                	console.info(file);
//                });
			};
			
			uploadSupport.fn.add = function() {
				this.entity.push($.extend({},this.bind));
				this.bind.videos = {};
				this.bind.videoIntroduce = "";
				this.cache.fileload.remove();
				this.bind.videoOk = "";
				this.bind.isOk = true;
			};
			uploadSupport.fn.save = function() {
				var _this = this;
				$.ajax({
					url : getServer() + "/flea/hclv/video/training/save.htmls",
					data : {
						'model' : JSON.stringify(_this.entity)
					},
					success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
						_this.$scope.grid.refresh();
						_this.slidebars.close();
						Util.alert(data.message);
					}
				});
			};
			return uploadSupportInit;
		});